<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>7_数组的reduce方法</title>
</head>
<body>
    <script>
        
        const todos = [
            {id: '001', name: '吃饭', done: true},
            {id: '002', name: '睡觉', done: true},
            {id: '003', name: '打代码', done: false},
            {id: '004', name: '打游戏', done: true}
        ]

        /**
         * 统计todos中的done为true的对象的数量
         */ 
        const count = todos.reduce((num, todoObj)=>{
            return num + (todoObj.done ? 1 : 0)
        }, 0)

        console.log(count);

    </script>
</body>
</html>